package grape.crm.rest.relation.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import grape.crm.rest.relation.form.RelationListForm;
import grape.crm.service.relation.query.RelationListQuery;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.crm.rest.relation.form.RelationCreateForm;
import grape.crm.rest.relation.form.RelationUpdateForm;
import grape.crm.rest.relation.form.RelationListPageForm;
import grape.crm.rest.relation.vo.RelationVo;
import grape.crm.rest.relation.mapper.RelationWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.crm.service.relation.po.Relation;
import grape.crm.service.relation.api.IRelationService;
import java.util.List;
/**
 * <p>
 * 客户关系字典 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-14
 */
@RestController
@RequestMapping("/crm/relation")
@Api(tags = "客户关系字典相关接口")
public class RelationController extends BaseController<RelationVo, Relation> {

    @Autowired
    private RelationWebMapper currentWebMapper;
    @Autowired
    private IRelationService currentService;



     @ApiOperation("添加客户关系字典")
     @PreAuthorize("hasAuthority('relation:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public RelationVo create(@RequestBody @Valid RelationCreateForm cf) {
         Relation po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询客户关系字典")
     @PreAuthorize("hasAuthority('relation:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public RelationVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除客户关系字典")
     @PreAuthorize("hasAuthority('relation:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新客户关系字典")
     @PreAuthorize("hasAuthority('relation:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public RelationVo update(@PathVariable String id,@RequestBody @Valid RelationUpdateForm uf) {
         Relation po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("不分页查询客户关系字典")
    @PreAuthorize("hasAuthority('relation:single:list')")
    @GetMapping("/list")
    @ResponseStatus(HttpStatus.OK)
    public List<RelationVo> list(RelationListForm listForm) {
        Relation po = currentWebMapper.formToPo(listForm);
        RelationListQuery relationListQuery = new RelationListQuery();
        relationListQuery.setPoQuery(po);
        return super.list(relationListQuery);
    }

    @ApiOperation("分页查询客户关系字典")
    @PreAuthorize("hasAuthority('relation:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<RelationVo> listPage(RelationListPageForm listPageForm) {
         Relation po = currentWebMapper.formToPo(listPageForm);
        RelationListQuery relationListQuery = new RelationListQuery();
        relationListQuery.setPoQuery(po);
        return super.listPage(relationListQuery,listPageForm);
     }

}
